﻿using Furion.DatabaseAccessor;
using Microsoft.EntityFrameworkCore;
using Mrhd.Core.Entities;
using Mrhd.Core.Extensions;
using Serilog;

namespace Mrhd.EntityFramework.Core
{
    [AppDbContext("SqlserverConnectionString", DbProvider.SqlServer)]
    public class MainDbContext : AppDbContext<MainDbContext>
    {
        public MainDbContext(DbContextOptions<MainDbContext> options) : base(options)
        {
            this.SavedChanges += (sender, args) =>
            {
                // 跟踪对商品表的更改
                var products = this.ChangeTracker.Entries<ProductEntity>();
                foreach (var item in products)
                {
                    Log.Warning("商品更新：" + item.Entity);
                }
            };
        }
    }
}